package com.simtop.hj.controller;

import com.kennycason.kumo.WordFrequency;
import com.simtop.hj.common.ServerResponse;
import com.simtop.hj.pojo.User;
import com.simtop.hj.pojo.WineWorld;
import com.simtop.hj.pojo.WordFrequencyData;
import com.simtop.hj.pojo.WordFrequencyPic;
import com.simtop.hj.service.UserService;
import com.simtop.hj.service.WineService;
import com.simtop.hj.utils.*;
import org.json.HTTP;
import org.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


@Controller
@CrossOrigin
@RequestMapping(value = "/wine")
public class WineController {

    private Logger logger= LoggerFactory.getLogger(WineController.class);

    @Autowired
    public WineService wineService;

    @Autowired
    public UserService userService;

    @Autowired
    public RedisUtil redisUtil;

    /**
     * 获取世界红酒销量
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineWorldSaleTheme",method = RequestMethod.GET)
    public ServerResponse<List> getWineWorldSaleTheme(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        return wineService.getWineWorldSaleTheme();
    }

    /**
     * 根据全球红酒销量获取年份
     * @param request
     * @param wineThemeId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineWorldSaleYear",method = RequestMethod.POST)
    public ServerResponse<List> getWineWorldSaleYear(HttpServletRequest request, @RequestBody String wineThemeId){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ") + 1);
        User u = JwtUtil.unsign(jwt, User.class);
        if (u == null) {
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject = new JSONObject(wineThemeId);
        Integer themeId = jsonObject.getInt("themeId");
        return wineService.getWineWorldSaleYear(themeId);
    }

    /**
     * 根据年份和主题条件筛选来获取数据
     * @param request
     * @param wineWorldSale
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineWorldSale",method = RequestMethod.POST)
    public ServerResponse<List<WineWorld>> getWineWorldSale(HttpServletRequest request, @RequestBody String wineWorldSale){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(wineWorldSale);
        String year=jsonObject.getString("year");
        Integer themeId=jsonObject.getInt("themeId");
        return ServerResponse.createBySuccess(wineService.getWineWorldSale(year,themeId));
    }

    /**
     * 获取全国销售量和产量的年份
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineNationYear",method = RequestMethod.GET)
    public ServerResponse getWineNationYear(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        List<String> yearList=wineService.getWineNationYear();
        return ServerResponse.createBySuccess(yearList);
    }

    /**
     * 获取全国红酒的销售量和产量
     * @param request
     * @param wineNationSale
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineNationYieldSale",method = RequestMethod.POST)
    public ServerResponse getWineNationYieldSale(HttpServletRequest request,@RequestBody String wineNationSale){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(wineNationSale);
        String year=jsonObject.getString("year");
        Integer choseWineCategory=jsonObject.getInt("choseWineCategory");
        return ServerResponse.createBySuccess(wineService.getWineNationYieldSale(year,choseWineCategory));
    }


    /**
     * 根据年份获取全国红酒前十的销售量
     * @param request
     * @param wineNationWideSale
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineNationwideSale",method = RequestMethod.POST)
    public ServerResponse getWineNationwideSale(HttpServletRequest request,@RequestBody String wineNationWideSale){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(wineNationWideSale);
        String year=jsonObject.getString("year");
        return ServerResponse.createBySuccess(wineService.getWineNationwideSale(year));
    }

    /**
     * 根据开始时间和截至时间来获取全球的红酒的销售量折线图
     * @param request
     * @param wineNationCountryYear
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineNationCountrySale",method = RequestMethod.POST)
    public ServerResponse getWineNationCountrySale(HttpServletRequest request,@RequestBody String wineNationCountryYear ){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(wineNationCountryYear);
        String beginYear=jsonObject.getString("beginYear");
        String endYear=jsonObject.getString("endYear");
        Integer countrySum=jsonObject.getInt("countrySum");
        return ServerResponse.createBySuccess(wineService.getWineNationCountrySale(beginYear,endYear,countrySum));
    }


    /**
     * 获取脏数据、容量脏数据、酒类脏数据、品类脏数据
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDirtyData",method = RequestMethod.POST)
    public ServerResponse getDirtyData(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        logger.info("脏数据处理");
        JSONObject jsonObject=new JSONObject(data);
        Integer num=jsonObject.getInt("num");
        Integer wineNum=jsonObject.getInt("wineNum");
        return wineService.getDirtyData(num,wineNum);
    }


    /**
     * 分页获取数据集
     * @param request
     * @param data（pageNum,pageSize）
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDirtyDataSet",method = RequestMethod.POST)
    public ServerResponse getDirtyDataSet(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        logger.info("获取脏数据的数据集");
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getDirtyDataSet(pageNum,pageSize);
    }


    /**
     * 红酒品牌规范化(随机Concha y Toro、禾富、Wolf Blass、露仙歌酒庄、纷赋酒庄)
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getBrandStandard",method = RequestMethod.GET)
    public ServerResponse getBrandStandard(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        return wineService.getBrandStandard();
    }


    /**
     * 子品牌规范化
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getSubsidiaryBrandStandard",method = RequestMethod.GET)
    public ServerResponse getSubsidiaryBrandStandard(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        return wineService.getSubsidiaryBrandStandard();
    }


    /**
     * 品牌规范化数据集(分页获取)
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProductStandard",method = RequestMethod.POST)
    public ServerResponse getProductStandard(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getProductStandard(pageNum,pageSize);
    }


    /**
     * 原始数据集（分页获取）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getRawDataSet",method = RequestMethod.POST)
    public ServerResponse getRawDataSet(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getRawDataSet(pageNum,pageSize);
    }

    /**
     * 获取价格规范化根据瓶数(2瓶或者6瓶)
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDataStandardByBottle",method = RequestMethod.POST)
    public ServerResponse getDataStandardByBottle(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorgetProductStandardMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        Integer bottleNum=jsonObject.getInt("bottleNum");
        return wineService.getDataStandardByBottle(pageNum,pageSize,bottleNum);
    }


    /**
     * 更新价格数据（价格数据规范化实验）
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDataStandardByUpdate",method = RequestMethod.GET)
    public ServerResponse getDataStandardByUpdate(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer serialNumber=jsonObject.getInt("serialNumber");
        return wineService.getDataStandardByUpdate(serialNumber);
    }


    /**
     * 获取价格规范化数据集(分页)
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDataStandard",method = RequestMethod.POST)
    public ServerResponse getDataStandard(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getDataStandard(pageNum,pageSize);
    }


    /**
     * 新旧世界缺失值(分页)
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getMissingValue",method = RequestMethod.POST)
    public ServerResponse getMissingValue(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getMissingValue(pageNum,pageSize);
    }


    /**
     * 品酒进阶（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getTastingAdvanced",method = RequestMethod.POST)
    public ServerResponse getTastingAdvanced(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getTastingAdvanced(pageNum,pageSize);
    }


    /**
     * 名庄数据集（分页）
     */
    @ResponseBody
    @RequestMapping(value = "/getFine",method = RequestMethod.POST)
    public ServerResponse getFine(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getFine(pageNum,pageSize);
    }


    /**
     * 葡萄品种（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "getGrapeVariety",method = RequestMethod.POST)
    public ServerResponse getGrapeVariety(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getGrapeVariety(pageNum,pageSize);
    }


    /**
     * 机器学习初始数据(分页)
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getMachineLearning",method = RequestMethod.POST)
    public ServerResponse getMachineLearning(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getMachineLearning(pageNum,pageSize);
    }


    /**
     * 价格数据离散化(分页)
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getPriceData",method = RequestMethod.POST)
    public ServerResponse getPriceData(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getPriceData(pageNum,pageSize);
    }


    /**
     * 字符数值化（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getCharacterNumeration",method = RequestMethod.POST)
    public ServerResponse getCharacterNumeration(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getCharacterNumeration(pageNum,pageSize);
    }


    /**
     * 数据归一化数据集（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getDataNormal",method = RequestMethod.POST)
    public ServerResponse getDataNormal(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getDataNormal(pageNum,pageSize);
    }


    /**
     * 海关风险监管(随机十条)
     * @param request
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/getCustomsRiskControl",method = RequestMethod.GET)
    public ServerResponse getCustomsRiskControl(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        //dasfasdf
        return wineService.getCustomsRiskControl();
    }


    /**
     * 平台活动预警(随机十条)
     * @param request
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getPlatformWarn",method = RequestMethod.GET)
    public ServerResponse getPlatformWarn(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        return wineService.getPlatformWarn();
    }


    /**
     * 商务谈判（随机十条）
     * @param request
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getBusiness",method = RequestMethod.GET)
    public ServerResponse getBusiness(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        //1213
        return wineService.getBusiness();
    }


    /**
     * 获取红酒官微粉丝数据（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWineFans",method = RequestMethod.POST)
    public ServerResponse getWineFans(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getWineFans(pageNum,pageSize);
    }


    /**
     * 京东评论数据（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getJdComment",method = RequestMethod.POST)
    public ServerResponse getJdComment(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getJdComment(pageNum,pageSize);
    }


    /**
     *京东评论数据（去短去重去水）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getJdCommentExcept",method = RequestMethod.POST)
    public ServerResponse getJdCommentExcept(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getJdCommentExcept(pageNum,pageSize);
    }


    /**
     * 产品画像评论文本分词词频统计（分页）
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProductWord",method = RequestMethod.POST)
    public ServerResponse getProductWord(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.creatgetNegativeProductEmotioneByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
//        HttpStatus.OK;
        return wineService.getProductWord(pageNum,pageSize);
    }

    /**
     * 产品画像评论文本分词不同维度关联词（分页）
     * @param request
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProductDimension",method = RequestMethod.GET)
    public ServerResponse getProductDimension(HttpServletRequest request){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        return wineService.getProductDimension();
    }


    /**
     * 产品画像情感分析词频统计
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProductEmotion",method = RequestMethod.POST)
    public ServerResponse getProductEmotion(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getProductEmotion(pageNum,pageSize);
    }


    /**
     * 产品画像情感分析正面负面情感词词频统计
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getNegativeProductEmotion",method = RequestMethod.POST)
    public ServerResponse getNegativeProductEmotion(HttpServletRequest request,@RequestBody String data){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        Integer num=jsonObject.getInt("num");
        return wineService.getNegativeProductEmotion(pageNum,pageSize,num);
    }

    /**
     * 文本分类分析
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getTextAnalysis",method = RequestMethod.POST)
    public ServerResponse getTextAnalysis(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getTextAnalysis(pageNum,pageSize);
    }

    /**
     * 文本分类分析话题高频词
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getTextAnalysisFrequency",method = RequestMethod.POST)
    public ServerResponse getTextAnalysisFrequency(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        Integer num=jsonObject.getInt("num");
        return wineService.getTextAnalysisFrequency(pageNum,pageSize,num);
    }

    /**
     * 百度新闻
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getBaiDuNews",method = RequestMethod.POST)
    public ServerResponse getBaiDuNews(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getBaiDuNews(pageNum,pageSize);
    }


    /**
     * 新浪新闻
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getSinaNews",method = RequestMethod.POST)
    public ServerResponse getSinaNews(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getSinaNews(pageNum,pageSize);
    }

    /**
     * 微博话题
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getWbTopic",method = RequestMethod.POST)
    public ServerResponse getWbTopic(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getWbTopic(pageNum,pageSize);
    }


    /**
     * 获取到知乎问答信息
     * @param request
     * @param data
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getZHWD",method = RequestMethod.POST)
    public ServerResponse getZHWD(HttpServletRequest request,@RequestBody String data){
//        String token = request.getHeader("Authorization");
//        String jwt = token.substring(token.lastIndexOf(" ")+1);
//        User u = JwtUtil.unsign(jwt,User.class);
//        if(u == null){
//            return ServerResponse.createByErrorMsg("token无效");
//        }
        JSONObject jsonObject=new JSONObject(data);
        Integer pageNum=jsonObject.getInt("pageNum");
        Integer pageSize=jsonObject.getInt("pageSize");
        return wineService.getZHWD(pageNum,pageSize);
    }




    /**
     * 删除jupyter用户的端口号
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteJupyterPort",method = RequestMethod.POST)
    public ServerResponse delete(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        /**
         * 用户使用jupyter超过1小时
         */
        if(((System.currentTimeMillis()-u.getLoginTime())/1000/3600)>=1){
            PythonUtil.delPort(u.getId()+"",u.getPassword());
            return ServerResponse.createByErrorMsg("本次项目操作时间已结束,请重新登录账号");
        }else{
            return ServerResponse.createBySuccessMsg("进入服务器连接");
        }
    }


    /**
     * 词云
     * @param request
     * @param getContentParticiple
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getContentParticiple",method = RequestMethod.POST)
    public ServerResponse getContentParticiple(HttpServletRequest request,@RequestBody String getContentParticiple){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        JSONObject jsonObject=new JSONObject(getContentParticiple);
        Integer wordSize=jsonObject.getInt("wordSize");
        Integer character=jsonObject.getInt("character");//特性 0为动词，1为名称，2为形容词
        WordFrequencyPic wordFrequencyPic=new WordFrequencyPic();
        if(!redisUtil.hasKey("wordFrequencyPic")){
            userService.insertRedisCiYun();
        }
        List<WordFrequencyData> wordFrequencyDataList= (List<WordFrequencyData>) redisUtil.lGetIndex("wordFrequencyPic",character);
        List<WordFrequency> wordFrequencyList = new ArrayList<>();
        List<WordFrequency> wordFrequencies = new ArrayList<>();
        for (int i = 0; i < wordFrequencyDataList.size(); i++) {
            WordFrequency wordFrequency=new WordFrequency(wordFrequencyDataList.get(i).getWord(),wordFrequencyDataList.get(i).getFrequency());
            wordFrequencyList.add(wordFrequency);
        }
        for (int i = 0; i < wordFrequencyList.size()&&i<=wordSize; i++) {
            WordFrequency wordFrequency= wordFrequencyList.get(i);
            wordFrequencies.add(wordFrequency);
        }
        wordFrequencyPic.setWordFrequencyList(wordFrequencies);
        return ServerResponse.createBySuccess(wordFrequencyPic);
    }


    /**
     * 情感分布
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getEmotionResult",method = RequestMethod.POST)
    public ServerResponse getEmotionResult(HttpServletRequest request){
        String token = request.getHeader("Authorization");
        String jwt = token.substring(token.lastIndexOf(" ")+1);
        User u = JwtUtil.unsign(jwt,User.class);
        if(u == null){
            return ServerResponse.createByErrorMsg("token无效");
        }
        return wineService.getEmotionResult();
    }

}
